
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;




public class FactoryEquipList extends JFrame{
    public FactoryEquipList(int num, String idDevice){


        SQLOperation sql=new SQLOperation();
        Container container = getContentPane();
        setLayout(new BorderLayout());
        JPanel titlePanel = new JPanel();

        JLabel title = new JLabel("Device Data");
        title.setFont(new Font("", Font.BOLD, 20));

        titlePanel.add(title);
        add(titlePanel,BorderLayout.NORTH);


        String[] dataBelongs={"Lamps","WindowsDoors","Humidity","Temperature"};
        String[][] dataInfo={{"isOn","timeStamp"},
                {"isOpen","timeStamp"},
                {"hygro","timeStamp"},
                {"tempNum","timeStamp"}};


        String[] attribute=new String[3];
        attribute[0]="Device_idDevice";
        for(int i=1;i<3;i++) attribute[i]=dataInfo[num][i-1];

        String condition="Device_idDevice";
        if(idDevice.equals("")){
            condition="shanchu";
            idDevice="1";
        }
        Object[][] selectData=sql.search(dataBelongs[num],attribute,condition,idDevice);
        System.out.println("111111111111");

        JTable dataList = new JTable(selectData, attribute);

        dataList.setRowHeight(30);
        dataList.setFont(new Font("", Font.PLAIN, 15));

        dataList.setEnabled(true);
        dataList.getTableHeader().setFont(new Font("", Font.BOLD, 20));
        JScrollPane scrollPane = new JScrollPane(dataList);

        add(scrollPane, BorderLayout.CENTER);


        JButton back = new JButton("Back");
        back.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                setVisible(false);
            }
        });

        JPanel buttons=new JPanel();
        buttons.add(back);

        add(buttons,BorderLayout.SOUTH);


        setSize(600,500);
        setResizable(false);
        setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
        setVisible(true);

    }
}
